package com.xnfh.equipment.viewmodel

import com.xnfh.common.bean.GateWayBean
import com.xnfh.common.bean.WarningBean
import com.xnfh.equipment.viewmodel.base.BaseTokenViewModel
import com.xnfh.framework.bean.RespStateData
import org.json.JSONObject

/**
 * @Description:
 * @Author: ziheng
 * @CreateDate: 2023/12/20 10:06
 * @UpdateUser: ziheng
 * @UpdateDate: 2023/12/20 10:06
 * @UpdateRemark: 更新说明
 */
class EquipmentViewModel : BaseTokenViewModel() {

    private val equipmentViewModelRes = EquipmentViewModelRes()
    val gateWayList = RespStateData<List<GateWayBean>>()
    val warningBean = RespStateData<WarningBean>()


    /**
     * 获取网关列表
     */
    fun requestGetewayList() = launch {
        val jsonObject = JSONObject()
        equipmentViewModelRes.requestGetewayList(creatRequestBody(jsonObject.toString()), gateWayList)
    }

    /**
     * 获取预警日志
     * @param gateWayId 网关id
     */
    fun requestWarningList(gateWayId: Int) = launch {
        val jsonObject = JSONObject()
        jsonObject.put("pageIndex", 1)//当前页码
        jsonObject.put("pageSize", 99)//页大小
        jsonObject.put("orderBy", 0)//排序字符串: 0 desc,1 asc
        val jsonObjectBean = JSONObject()
        jsonObjectBean.put("gatewayid", gateWayId)// 网关id
        jsonObjectBean.put("msgType", 2)//0 为不限制，1 系统日志，2 预警日志
        jsonObjectBean.put("msgPriority", 0)//消息大类，0 为不限制
        jsonObject.put("searchInfo", jsonObjectBean)
        equipmentViewModelRes.requestWarningList(
            creatRequestBody(jsonObject.toString()),
            warningBean
        )
    }


}